#include <bits/stdc++.h>
// 2025/01/22
// tag: 
// Author: Zhang Muen
using namespace std;

int n, m, nums[100001];

bool check(int maxn){
    int cnt = 1, sum = 0;
    for (int i = 1; i <= n; i++){
        if (sum + nums[i] > maxn)
            cnt++, sum = nums[i];
        else
            sum += nums[i];
    }
    return cnt <= m;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    int l = 0, r = 0, ans = 0;
    for (int i = 1; i <= n; i++)
        cin >> nums[i], r += nums[i], l = max(l, nums[i]);
    while (l <= r){
        int mid = (l + r) / 2;
        if (check(mid))
            ans = mid, r = mid - 1;
        else
            l = mid + 1;
    }
    cout << ans;
    return 0;
}